//
//  Getter.m
//  Staff
//
//  Created by caiyao on 1/13/15.
//
//

#import "Getter.h"
#import "NSData-AES.h"

@implementation Getter

- (void)excute {
    
    NSString *key = [self.command.functionParamsDic objectForKey:@"key"];
    
    if (self.command.callbackJS == nil || key == nil)
    {
        // params is missing fail to handle
        [self excuteNonHookFoundCallback];
        return;
    }
    
    NSString *value = @"";
    
    NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
 
    if ([key isEqualToString:@"customerInfo"]) {
        NSData *data = [defs objectForKey:key];
        NSData *encryptedData = [NSData dataWithData:data];
        NSData *saveData = [encryptedData AES256DecryptWithKey:secureToken];
        value = [[NSString alloc] initWithData:saveData encoding:NSUTF8StringEncoding];
    } else {
        value =[defs objectForKey:key];
    }
        
    if(value != nil)
    {
        
        [self excuteCallBackJSWithParameters:value];
        
    }
    else
    {
        [self excuteCallBackJSWithParameters:nil];
    }
}

@end
